import { NgModule, Optional, SkipSelf } from '@angular/core';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { SharedModule } from '../shared/shared.module';
import { MatIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
import { HttpClientModule} from '@angular/common/http';
import { loadSvgResources } from '../utils/svg.util';


/**
 * @user: 180300
 * @date: 2018/4/17 10:48
 * @description: 核心模块 （只导入一次）
 *
 */
@NgModule({
  imports: [
    HttpClientModule,
    SharedModule
  ],
  declarations: [
    HeaderComponent,
    FooterComponent,
    SidebarComponent
  ],
  exports: [
    HeaderComponent,
    FooterComponent,
    SidebarComponent
  ]
})
export class CoreModule {
  constructor(
    @Optional() @SkipSelf() parent: CoreModule,
    iconRegister: MatIconRegistry,
    sanitizer: DomSanitizer
  ) {
    if (parent) {
      throw new Error('模块已存在，不能重复加载');
    }
    // 调用svg转icon util工具类
    loadSvgResources(iconRegister, sanitizer);
  }
}
